package com.saianfu.flowable.demo.config

import org.flowable.engine.ProcessEngineConfiguration
import org.flowable.spring.SpringProcessEngineConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.io.ResourceLoader
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
import org.springframework.jdbc.datasource.DataSourceTransactionManager
import java.io.IOException
import javax.sql.DataSource

/**
 * @description Flowable配置类
 */
@Configuration
class FlowableConfig {
    @Bean
    @Throws(IOException::class)
    fun processEngine(transactionManager: DataSourceTransactionManager?, dataSource: DataSource?) {
        val configuration = SpringProcessEngineConfiguration()
        //自动部署已有的流程文件
        val resources = PathMatchingResourcePatternResolver().getResources(ResourceLoader.CLASSPATH_URL_PREFIX + "processes/*.bpmn")
        configuration.transactionManager = transactionManager
        // 执行工作流对应的数据源
        configuration.dataSource = dataSource
        // 是否自动创建流程引擎表
        configuration.databaseSchemaUpdate = ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE
        configuration.deploymentResources = resources
        //configuration.setDbIdentityUsed(false);
        //configuration.setAsyncExecutorActivate(false);
        // 流程历史等级
        //configuration.setHistoryLevel(HistoryLevel.FULL);
        // 流程图字体
        configuration.activityFontName = "宋体"
        configuration.annotationFontName = "宋体"
        configuration.labelFontName = "宋体"
        //return configuration;
    }
}